<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <header th:replace="header::html"></header>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span style="color: red">*</span>字典名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="dictName" th:value="${MyDict.dictName}" lay-verify="required" autocomplete="off" placeholder="请输入字典名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        字典描述</label>
                    <div class="layui-input-block">
                        <input type="text" name="description" th:value="${MyDict.description}" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span style="color: red">*</span>排序</label>
                    <div class="layui-input-block">
                        <input type="text"  name="sort"th:value="${MyDict.sort}" lay-verify="sort" autocomplete="off" placeholder="请输入排序" class="layui-input">
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="dict-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(dict-save)', function(data){
            $.ajax({
                url:'/api/dict',
                data:JSON.stringify(data.field),
                dataType:'json',
                contentType:'application/json',
                type:'put',
                success:function(result){
                    if(result.success){
                        layer.msg(result.msg,{icon:1,time:1000},function(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dict-type-table");
                        });
                    }else{
                        layer.msg(result.msg,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
        form.verify({
            sort:  [
                /^[1-9]\d*$/
                ,'只能是整数哦'
            ],
        })
    })
</script>
</body>
</html>
